<template>
  <div class="createPost-container">
    <el-form ref="postForm" :model="DtuDetailForm" :rules="rules"  class="form-container">
      <div class="createPost-main-container">
        <el-row>
          <el-col :span="24">
            <el-form-item style="margin-bottom: 20px;"  label="storageId:"> : {{DtuDetailForm.storageId}} </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item style="margin-bottom: 20px;"  label="dtuCode:"> : {{DtuDetailForm.dtuCode}} </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item style="margin-bottom: 20px;"  label="名称:"> {{DtuDetailForm.dtuName}} </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item style="margin-bottom: 20px;" label="model:" >  {{DtuDetailForm.model}} </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item style="margin-bottom: 20px;" label="类型:" >  {{DtuDetailForm.type}} </el-form-item>
        </el-row>
        <el-row>
          <el-form-item style="margin-bottom: 20px;" label="描述:" > {{DtuDetailForm.dtuDesc}} </el-form-item>
        </el-row>
        <el-row>
          <el-form-item style="margin-bottom: 20px;" label="状态:" >  {{DtuDetailForm.status}} </el-form-item>
        </el-row>
        <el-row>
          <el-form-item style="margin-bottom: 20px;" label="创建时间:" >  {{DtuDetailForm.createTime}} </el-form-item>
        </el-row>
      </div>
    </el-form>
  </div>
</template>

<script>
import Tinymce from '@/components/Tinymce'
import Upload from '@/components/Upload/singleImage3'
import MDinput from '@/components/MDinput'
import Sticky from '@/components/Sticky' // 粘性header组件
import { validateURL } from '@/utils/validate'
import { dtuDetail } from '@/api/dtu'
import { userSearch } from '@/api/remoteSearch'
import Warning from './Warning'
import { CommentDropdown, PlatformDropdown, SourceUrlDropdown } from './Dropdown'

const defaultForm = {
  id:'',
  storageId: '',
  dtuCode: '',//用户号,userId
  dtuName: '', //用户名
  model: '', //自定义仓库名
  type: '', //用户手机号
  dtuDesc: '', //用户类型,1管理员,2技术员,3租户
  status: 1, //
  createTime: '', //二级仓库号,roomId
  updateTime: ''
}

export default {
  name: 'FaultcodeDetail',
  components: { Tinymce, MDinput, Upload, Sticky, Warning, CommentDropdown, PlatformDropdown, SourceUrlDropdown },
  props: {
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    const validateRequire = (rule, value, callback) => {
      consoel.log(value)
      if (value === '') {
        this.$message({
          message: rule.field + '为必传项',
          type: 'error'
        })
        callback(new Error(rule.field + '为必传项'))
      } else {
        callback()
      }
    }
    const validateSourceUri = (rule, value, callback) => {
      if (value) {
        if (validateURL(value)) {
          callback()
        } else {
          this.$message({
            message: '外链url填写不正确',
            type: 'error'
          })
          callback(new Error('外链url填写不正确'))
        }
      } else {
        callback()
      }
    }
    return {
      DtuDetailForm: Object.assign({}, defaultForm),
      loading: false,
      userListOptions: [],
      rules: {

      }
    }
  },
  computed: {
    contentShortLength() {
      return this.DtuDetailForm.content_short.length
    }
  },
  created() {
    if (this.isEdit) {
      const id = this.$route.query && this.$route.query.id
      this.fetchData(id)
    } else {
      this.DtuDetailForm = Object.assign({}, defaultForm)
    }
  },
  methods: {
    fetchData(id) {
      dtuDetail({ id: id }).then(response => {
        this.DtuDetailForm = response.data.data
        console.log(this.DtuDetailForm)
      }).catch(err => {
        console.log(err)
      })
    },
    submitForm() {
      // this.postForm.display_time = parseInt(this.display_time / 1000)
      // console.log(this.postForm)
      // this.$refs.postForm.validate(valid => {
      //   if (valid) {
      //     this.loading = true
      //     this.$notify({
      //       title: '成功',
      //       message: '发布文章成功',
      //       type: 'success',
      //       duration: 2000
      //     })
      //     this.postForm.status = 'published'
      //     this.loading = false
      //   } else {
      //     console.log('error submit!!')
      //     return false
      //   }
      // })
    },
    getRemoteUserList(query) {
      userSearch(query).then(response => {
        if (!response.data.items) return
        this.userListOptions = response.data.items.map(v => v.name)
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.createPost-container {
  position: relative;
  .createPost-main-container {
    padding: 40px 45px 20px 50px;
    .postInfo-container {
      position: relative;
      @include clearfix;
      margin-bottom: 10px;
      .postInfo-container-item {
        float: left;
      }
    }
    .editor-container {
      min-height: 500px;
      margin: 0 0 30px;
      .editor-upload-btn-container {
        text-align: right;
        margin-right: 10px;
        .editor-upload-btn {
          display: inline-block;
        }
      }
    }
  }
  .word-counter {
    width: 40px;
    position: absolute;
    right: -10px;
    top: 0px;
  }
}
</style>
